package proto;

import java.awt.Color;


/**
 * Base class for all field types of the tiles.
 * @author Bitjaeger
 *
 */
public class Field {
    private Point position;    // Stores the position of the field in the tile
    private Field[] neighbors;  // LRUD
    protected Color color;

    public Field(Color c) {
        neighbors = new Field[4];
        color = c;
    }

    public Field() {
        neighbors = new Field[4];
        color = Color.WHITE;
    }

    /**
    * Tell the color if it can enter this field, that is: it's not a brick.
    * @return whether the color can come.
    */
    public boolean CanICome() {
        return (color == Color.WHITE || color == Color.BLUE || color == Color.ORANGE);
    }

    public Field GetNeighbor(Direction direction) {
        switch(direction){
            case LEFT:  return neighbors[0];
            case RIGHT: return neighbors[1];
            case UP:    return neighbors[2];
            case DOWN:  return neighbors[3];
         }
        return null;
    }

    public Point GetPosition() {
        return position;
    }

    /**
    * Empty method for field actions, overridden in all inherited classes.
    * @param color The color to perform the actions on.
    */
    public void DoAction(Stickman stickman) {
    // insert code here in inherited classes
        this.color = stickman.GetColor();
    }

    public void Leave(){
        color = Color.WHITE;
    }

    /**
     *
     * @param direction The direction of the neighbor to be set
     * @param field The field you want to assign to the neighbor
     */
    public void SetNeighbor(Direction direction, Field field) {
        switch(direction){
            case LEFT:  neighbors[0] = field;
            case RIGHT: neighbors[1] = field;
            case UP:    neighbors[2] = field;
            case DOWN:  neighbors[3] = field;
        }
    }

    public void Init(Point point) {
        position = point;
    }

    public Color GetColor() {
        return color;
    }
}